package com.example.polarity;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;

public class Bullet {
	
	float xPos;
	float yPos;
	float angle;
	
	Bitmap bulletImage;
	Matrix matrix;
	
	boolean init = true;
	
	public boolean destroy = false;
	
	public Bullet(float x, float y, Bitmap image, float a)
	{
		xPos = x;
		yPos = y;
		angle = a;
		bulletImage = image;
		matrix = new Matrix();
	}
	
	public void draw(Canvas canvas, Player player, int ScreenWidth, int ScreenHeight)
	{
		
		if(init)
		{
			xPos = player.x + (player.PlayerImage.getWidth() /2);
			yPos = player.y + (player.PlayerImage.getHeight() / 2);
			matrix.setTranslate(xPos, yPos );
			matrix.postRotate(angle, this.xPos + (this.bulletImage.getWidth() /2), this.yPos + (this.bulletImage.getHeight() / 2));
			canvas.drawBitmap(bulletImage,matrix, null);
			
			init = false;
		}
		else
		{
			xPos += (float) Math.cos(Math.toRadians(angle)) * 5;
			yPos += (float) Math.sin(Math.toRadians(angle)) * 5;
			
			matrix.setTranslate(xPos, yPos);
			matrix.postRotate(angle, this.xPos + (this.bulletImage.getWidth() /2), this.yPos + (this.bulletImage.getHeight() / 2));
			
			canvas.drawBitmap(bulletImage,matrix, null);
		}
		
	}

}
